﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Diagnostics;
using System.IO;


namespace СityDelivery
{
	public partial class MainForm : Form
	{
		public MainForm()
		{
			InitializeComponent();
		}

		XMLFile OSMFile;
		XMLFileProcessing OSMFileProcessing;
		private void buttonOpenJOSM_Click(object sender, EventArgs e)
		{
			CityMap myMap = new CityMap();
			if (myMap.Start() == true)
			{
				labelStatus.Text = "Открытие JOSM.../без ошибок";
			}
			else
			{
				labelStatus.Text = "Открытие JOSM.../ошибка!";
			}
		}

		private void buttonOpenXML_Click(object sender, EventArgs e)
		{
			OpenFileDialog openXMLFileDialog = new OpenFileDialog();
			openXMLFileDialog.ShowDialog();
			if (System.IO.Path.GetExtension(openXMLFileDialog.FileName) == ".osm")
			{

				OSMFile = new XMLFile();

				if (OSMFile.OpenFile(openXMLFileDialog.FileName))
				{
					labelStatus.Text = "Файл карты успешно загружен";
					buttonSettings.Enabled = true;
					buttonCalcPath.Enabled = true;
				}
				else
					labelStatus.Text = "Произошла ошибка в загрузке !";

			}


			// Подсчет кол-ва перекрестков
			OSMFileProcessing = new XMLFileProcessing();
			OSMFileProcessing.StartFileScanning(OSMFile.GetXML());
			OSMFileProcessing.getInfoFromFile(OSMFile.GetXML());
			Data.ConnectivityMatrix = OSMFileProcessing.CreateMatrix();
		}

		private void buttonCalcPath_Click(object sender, EventArgs e)
		{
			if (Data.parametersFlag)
			{
				Algorithm doAlgo = new Algorithm();
				Data.paths = doAlgo.GetShortPaths(Data.ConnectivityMatrix);
				float[,] a = Data.paths;

				doAlgo.fillRemainList();
				List<int> finalOrder = doAlgo.GetOrderList(0);
				doAlgo.MakeShedule(finalOrder);
				buttonShowPath.Enabled = true;
			}
			else
			{
				MessageBox.Show("Вы не ввели параметры!", "Ошибка");
			}
		}

		private void buttonShowPath_Click(object sender, EventArgs e)
		{

			new ShowPathForm().Show();
		}


		private void buttonSettings_Click(object sender, EventArgs e)
		{
			new SettingParametersForm().Show();
		}
	}
}